Passed
Push — master ( 242434...715ae1 )
by Mathieu
01:40
created

Event   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 86
dl 0
loc 98
rs 10
c 0
b 0
f 0

9 Functions

Rating   Name   Duplication   Size   Complexity  
A getId 0 3 1
A getDate 0 3 1
A update 0 13 1
A getType 0 3 1
A getSummary 0 3 1
A getTask 0 3 1
A getUser 0 3 1
A getProject 0 3 1
A getTime 0 3 1
1
import {Column, Entity, ManyToOne, PrimaryGeneratedColumn} from 'typeorm';
2
import {User} from '../User/User.entity';
3
import {Task} from '../Task/Task.entity';
4
import {Project} from '../Project/Project.entity';
5
6
export enum EventType {
7
  MISSION = 'mission',
8
  SUPPORT = 'support',
9
  DOJO = 'dojo',
10
  FORMATION_CONFERENCE = 'formationConference',
11
  HOLIDAY = 'holiday',
12
  MEDICAL_LEAVE = 'medicalLeave',
13
  OTHER = 'other'
14
}
15
16
@Entity()
17
export class Event {
18
  // Times spent are stored in base 100
19
  public static readonly MAXIMUM_TIMESPENT_PER_DAY: number = 100;
20
  public static readonly WORKED_TYPES: string[] = [
21
    EventType.MISSION,
22
    EventType.SUPPORT,
23
    EventType.DOJO,
24
    EventType.FORMATION_CONFERENCE
25
  ];
26
27
  @PrimaryGeneratedColumn('uuid')
28
  private id: string;
29
30
  @Column('enum', {enum: EventType, nullable: false})
31
  private type: EventType;
32
33
  @Column({type: 'integer', nullable: false})
34
  private time: number;
35
36
  @Column({type: 'date', nullable: false})
37
  private date: string;
38
39
  @Column({type: 'varchar', nullable: true})
40
  private summary: string;
41
42
  @ManyToOne(type => Project, {nullable: true})
43
  private project: Project;
44
45
  @ManyToOne(type => Task, {nullable: true})
46
  private task: Task;
47
48
  @ManyToOne(type => User, {nullable: false})
49
  private user: User;
50
51
  constructor(
52
    type: EventType,
53
    user: User,
54
    time: number,
55
    date: string,
56
    project?: Project,
57
    task?: Task,
58
    summary?: string
59
  ) {
60
    this.type = type;
61
    this.user = user;
62
    this.time = time;
63
    this.date = date;
64
    this.project = project;
65
    this.task = task;
66
    this.summary = summary;
67
  }
68
69
  public getId(): string {
70
    return this.id;
71
  }
72
73
  public getType(): string {
74
    return this.type;
75
  }
76
77
  public getTime(): number {
78
    return this.time;
79
  }
80
81
  public getDate(): string {
82
    return this.date;
83
  }
84
85
  public getSummary(): string | null {
86
    return this.summary;
87
  }
88
89
  public getProject(): Project | null {
90
    return this.project;
91
  }
92
93
  public getTask(): Task | null {
94
    return this.task;
95
  }
96
97
  public getUser(): User {
98
    return this.user;
99
  }
100
101
  public update(
102
    type: EventType,
103
    time: number,
104
    project?: Project,
105
    task?: Task,
106
    summary?: string
107
  ): void {
108
    this.type = type;
109
    this.time = time;
110
    this.project = project;
111
    this.task = task;
112
    this.summary = summary;
113
  }
114
}
115